package com.ruoyi.project.work.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.work.domain.WorkProcess;
import com.ruoyi.project.work.service.IWorkProcessService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 工作流程Controller
 * 
 * @author wyh
 * @date 2024-08-12
 */
@RestController
@RequestMapping("/play/process")
public class WorkProcessController extends BaseController
{
    @Autowired
    private IWorkProcessService workProcessService;

    /**
     * 查询工作流程列表
     */
    @PreAuthorize("@ss.hasPermi('play:process:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkProcess workProcess)
    {
        startPage();
        List<WorkProcess> list = workProcessService.selectWorkProcessList(workProcess);
        return getDataTable(list);
    }

    /**
     * 导出工作流程列表
     */
    @PreAuthorize("@ss.hasPermi('play:process:export')")
    @Log(title = "工作流程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkProcess workProcess)
    {
        List<WorkProcess> list = workProcessService.selectWorkProcessList(workProcess);
        ExcelUtil<WorkProcess> util = new ExcelUtil<WorkProcess>(WorkProcess.class);
        util.exportExcel(response, list, "工作流程数据");
    }

    /**
     * 获取工作流程详细信息
     */
    @PreAuthorize("@ss.hasPermi('play:process:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(workProcessService.selectWorkProcessById(id));
    }

    /**
     * 新增工作流程
     */
    @PreAuthorize("@ss.hasPermi('play:process:add')")
    @Log(title = "工作流程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkProcess workProcess)
    {
        return toAjax(workProcessService.insertWorkProcess(workProcess));
    }

    /**
     * 修改工作流程
     */
    @PreAuthorize("@ss.hasPermi('play:process:edit')")
    @Log(title = "工作流程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkProcess workProcess)
    {
        return toAjax(workProcessService.updateWorkProcess(workProcess));
    }

    /**
     * 删除工作流程
     */
    @PreAuthorize("@ss.hasPermi('play:process:remove')")
    @Log(title = "工作流程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workProcessService.deleteWorkProcessByIds(ids));
    }
}
